Uec3.RetailCompanyMessageWindow = Ext.extend(Ext.app.Module, {
	id : 'retailCompanyMessage',
	type : 'retailCompanyMessage/company',

	/**
	 * Initialize this module. This function is called at startup (page
	 * load/refresh).
	 */
	init : function(initParams) {
	},

	getComponents : function(params) {

		var company_dist_cmb;
		var company_city_cmb;
		var company_prov_cmb;
		var company_ajax;
		var companyForm;

		var componentCompanyInits = function() {

			// 区县下拉框
			company_dist_cmb = getDistrictCombox(Uec3.App.Constants.homeUrl);
			company_dist_cmb.anchor="99%";
			company_dist_cmb.setDisabled(true);
		//	company_dist_cmb.setWidth(120);
			// 城市下拉框
			company_city_cmb = getCityCombox(Uec3.App.Constants.homeUrl,
					company_dist_cmb);
			company_city_cmb.anchor="99%";
			company_city_cmb.setDisabled(true);
		//	company_city_cmb.setWidth(120);
			// 省份下拉框
			company_prov_cmb = getProvinceCombox(Uec3.App.Constants.homeUrl,
					company_city_cmb, company_dist_cmb);
			company_prov_cmb.anchor="99%";
			company_prov_cmb.setDisabled(true);
		//	company_prov_cmb.setWidth(120);

			var formReader = new Ext.data.JsonReader(

			{
						root : 'root'
					}, [{
								name : 'id',
								type : 'int'
							}, {
								name : 'email',
								type : 'string'
							}, {
								name : 'name',
								type : 'string'
							}, {
								name : 'contactorIdentityCode',
								type : 'string'
							}, {
								name : 'fax',
								type : 'string'
							}, {
								name : 'invoicAddress',
								type : 'string'
							}, {
								name : 'bankName',
								type : 'string'
							}, {
								name : 'bankCode',
								type : 'string'
							},{
								name : 'address',
								type : 'string'
							}, {
								name : 'qq',
								type : 'string'
							}, {
								name : 'msn',
								type : 'string'
							}, {
								name : 'web',
								type : 'string'
							}, 
							{
								name : 'contactor',
								type : 'string'
							}, {
								name : 'taxCode',
								type : 'string'
							}, {
								name : 'areaId',
								type : 'int'
							}, {
								name : 'code',
								type : 'string'
							}, {
								name : 'simpleName',
								type : 'string'
							}, {
								name : 'nameEn',
								type : 'string'
							}, {
								name : 'business',
								type : 'string'
							}, {
								name : 'postcode',
								type : 'string'
							}, {
								name : 'tel',
								type : 'string'
							}]

			);

			company_ajax = new Ext.data.Connection();

			companyForm = new Ext.form.FormPanel({
				labelAlign : 'right',
				frame : true,
				height : 370,
				labelWidth : 80,
				loadingText : '加载数据中...',
				buttonAlign : 'center',
				url : '',
				reader : formReader,
				items : [ {
      xtype:'fieldset',
      title: '基本信息',
      height:125,
      collapsed: false,
      items :[
        {
          layout:'column',
          items:[
           {
             columnWidth:0.5,
             items:[
               {
                layout:'form',
                labelWidth:70,
                items:[{name : 'id',fieldLabel : 'ID', xtype : 'hidden'},
                       {name : 'areaId',fieldLabel : 'areaId', xtype : 'hidden'},
                  	{xtype:'textfield',fieldLabel:'公司名称', name:'name',width:150,anchor:'99%',style : {
							color : '#aaaaaa'
						},readOnly:true}]
               },
               	{
                layout:'form',
                labelWidth:70,
                items:[
                  	{xtype:'textfield',fieldLabel : '公司简称',name : 'simpleName',anchor:'99%',style : {
						color : '#aaaaaa'
					},readOnly:true}]
               },
               		{
                layout:'column',
                items:[{
                    columnWidth:0.5,
                    items:[{
                         layout:'form',
                         labelWidth:70,
                         items:[{xtype:'textfield',fieldLabel:'负责人/法人',name:'contactor',style:{
								color : '#aaaaaa'
							},readOnly:true, anchor:'99%'} ]}]
                   },{
                    columnWidth:0.5,
                    items:[{
                         layout:'form',
                         labelAlign:'right',
                         labelWidth:70,
                         items:[{ xtype:'textfield',fieldLabel:'法人身份证',name:'contactorIdentityCode',anchor:'99%',style : {
								color : '#aaaaaa'
							},readOnly:true}]}]
                  }
                ]
               }]
           },{
             columnWidth:0.5,
             items:[{
                layout:'form',
                labelWidth:56,
                labelAlign:'right',
                items:[{xtype:'textfield',fieldLabel:'经营项目',name:'business',anchor:'99%',style : {
					color : '#aaaaaa'
				},readOnly:true}]
               },{
                layout:'form',
                labelWidth:70,
                items:[
                  	{xtype:'textfield',fieldLabel : '英文名称',style : {
						color : '#aaaaaa'
					},readOnly:true,anchor:'99%',name : 'nameEn'}]
               },{
                layout:'column',
                
                items:[{
                    columnWidth:0.5,
                    items:[{
                         layout:'form',
                         labelAlign:'right',
                         labelWidth:56,
                         items:[{xtype:'textfield',fieldLabel:'税号',name:'taxCode',anchor:'99%',style : {
								color : '#aaaaaa'
							},readOnly:true}]}]
                  },{
                    columnWidth:0.5,
                    items:[{
                         layout:'form',
                         labelWidth:70,
                         labelAlign:'right',
                         items:[{xtype:'textfield',fieldLabel:'工商注册码',name:'code',anchor:'99%',style : {
								color : '#aaaaaa'
							},readOnly:true}]}]
                  }]
                }]
               }]
             }]
      },{
		xtype : 'fieldset',
		title : '联系方式',
		height: 145,		
		items:[{
		        layout:'column',
		        items:[
			           {
			        	   columnWidth:0.2,
			             items:[{
			                 layout:'form',
			                 labelWidth:70,
			                 items:[company_prov_cmb]}]
			           },{
			           	 columnWidth:0.15,
			             items:[{
			                 layout:'form',
			                 labelWidth:30,
			                 items:[company_city_cmb]}]
			           },{
			           	 columnWidth:0.15,
			             items:[{
			             		layout:'form',
			             		labelWidth:30,
			                    items:[company_dist_cmb]}]
			           },{
		           	 columnWidth:0.25,
		             items:[{
		                 layout:'form',
		                 labelWidth:56,
		                 labelAlign:'right',
		                 items:[{xtype:'textfield',fieldLabel : '通讯地址',name : 'address',anchor:'99%',style : {
								color : '#aaaaaa'
							},readOnly:true}]}]
		           },{
		           	 columnWidth:0.25,
		             items:[{
		                 layout:'form',
		                 labelWidth:70,
		                 labelAlign:'right',
		                 items:[{xtype:'textfield',fieldLabel : '邮编',name : 'postcode',style : {
								color : '#aaaaaa'
							},readOnly:true,anchor:'99%'}]}]
		           }
		        ]
		       },{
		       	 layout:'column',
		       	 items:[
		       	   {
		       	     columnWidth:0.25,
		       	     items:[{
		       	         layout:'form',
		       	         labelWidth:70,
		       	         items:[{xtype:'textfield',fieldLabel:'开户行',name:'bankName',style : {
								color : '#aaaaaa'
							},readOnly:true,anchor:'99%'}]
		       	       },{
		       	       	 layout:'form',
		       	       	 labelWidth:70,
		       	         items:[{xtype:'textfield',fieldLabel:'联系电话',name:'tel',	style : {
								color : '#aaaaaa'
							},readOnly:true, anchor:'99%'}]
		       	       }
		       	     ]
		       	   },{
		             columnWidth:0.25,
		       	     items:[{
		       	         layout:'form',
		       	         labelWidth:70,
		       	         labelAlign:'right',
		       	         items:[{xtype:'textfield',fieldLabel:'银行账号',name:'bankCode',style : {
								color : '#aaaaaa'
							},readOnly:true,anchor:'99%'}]
		       	       },{
		       	       	 layout:'form',
		       	       	 labelWidth:70,
		       	       	 labelAlign:'right',
		       	         items:[{xtype:'textfield',fieldLabel:'传真电话',style : {
								color : '#aaaaaa'
							},readOnly:true,name:'fax',anchor:'99%'}]
		       	       }
		       	     ]
		       	   },{
		             columnWidth:0.5,
		       	     items:[{
		       	     		layout:'form',
		       	            labelWidth:56,
		       	            labelAlign:'right',
		       	            items:[{xtype:'textfield',fieldLabel:'发票地址',style : {
								color : '#aaaaaa'
							},readOnly:true,name:'invoicAddress',anchor:'99%'}]
		       	       },{
		       	       	 layout:'column',
		       	         items:[{
		       	            columnWidth:.5,
		       	            items:[{
		       	                layout:'form',
		       	                labelWidth:56,
		       	                labelAlign:'right',
		       	                items:[{xtype : 'numberfield',
														fieldLabel : 'QQ号',
														name : 'qq',
														style : {
															color : '#aaaaaa'
														},
														readOnly:true}]}]
		       	           },{
		       	           	columnWidth:.5,
		       	            items:[{
		       	                layout:'form',
		       	                labelWidth:70,
		       	                labelAlign:'right',
		       	                items:[{xtype:'textfield',fieldLabel:'E-Mail',name:'email',anchor:'99%',
														vtype : 'email',
														style : {
															color : '#aaaaaa'
														},
														readOnly:true}]}]
		       	           }]}]
		       	   }]
		       },{
		       	 layout:'column',
		       	 items:[{
		             columnWidth:0.5,
		       	     items:[{layout:'form',
		       	            labelWidth:56, labelAlign:'right',items:[{xtype : 'textfield',fieldLabel : 'MSN号',
														name : 'msn',
														anchor:'99%',
														style : {
															color : '#aaaaaa'
														},
														readOnly:true}]}]
		       	   },{
		             columnWidth:0.5,
		       	     items:[{
		       	     		layout:'form',
		       	            labelWidth:56,
		       	            labelAlign:'right',
		       	            items:[{xtype : 'textfield',fieldLabel:'网址',style : {
								color : '#aaaaaa'
							},readOnly:true,name : 'web',anchor:'99%'}]
		       	       }]
		       	   }]
		       }]
	}],
				buttons : [{
					text : '关闭',

					handler : function() {

						companyForm.ownerCt.close();

					},
					style : "margin-left:20px"
				}]
			});
			// 加载form表单数据
			companyForm.getForm().load({
				url : Uec3.App.Constants.homeUrl
						+ '/company/query_company!query.do',
						params: {
				        companyId : params.companyId
		              },
  					waitMsg : '加载数据中...',
				    success : function(form, action) {
			                
	                       // Ext.MessageBox.alert("提示","加载数据成功");
							
					},

						failure : function(form, action) {
			                
							Ext.MessageBox.alert("提示","加载数据失败");
					}
			});

			
			
		};

		var controlCompanyEvent = function() {

			/*company_prov_cmb.on('select', function(combox) {

						companyForm.getForm().findField('areaId')
								.setValue(combox.getValue());

					});

			company_city_cmb.on('select', function(combox) {

						companyForm.getForm().findField('areaId')
								.setValue(combox.getValue());

					});

			company_dist_cmb.on('select', function(combox) {

						companyForm.getForm().findField('areaId')
								.setValue(combox.getValue());

					});

			company_ajax.on('beforerequest', function() {

						Ext.MessageBox.wait("更新数据中...", "提示");
					});

			company_ajax.on('requestcomplete', function() {

						Ext.MessageBox.hide();
					});
*/
			companyForm.getForm().on('actioncomplete', function(form) {
				
			    var rootFirstValue=companyForm.getForm().reader.jsonData.root;
		
				company_prov_cmb
				.setRawValue(rootFirstValue.province);
		        company_city_cmb
				.setRawValue(rootFirstValue.city);
		        company_dist_cmb
				.setRawValue(rootFirstValue.district);

		if (rootFirstValue.province!= "") {

			company_city_cmb
					.getStore()
					.setBaseParam(
							"prov",
							rootFirstValue.provinceId);
			company_city_cmb.getStore().load();

		}

		if (rootFirstValue.city!= "") {

			company_dist_cmb.getStore().setBaseParam("city",
					rootFirstValue.cityId);
			company_dist_cmb.getStore().load();

		}

			});

		};

		componentCompanyInits();

		controlCompanyEvent();

		return companyForm;

	},

	/**
	 * Create this modules window here.
	 */
	createWindow : function(params) {
		var desktop = this.app.getDesktop();
		var win = desktop.getWindow('retailCompanyMessage');
		var module = this;
		if (!win) {
			win = desktop.createWindow({
						id : 'retailCompanyMessage',
						title : '公司详细信息',
						width :900,
						height : 370,
						iconCls : 'acc-icon',
						autoScroll : true,
						shim : false,
						animCollapse : false,
						constrainHeader : true,
						maximizable : false,
						resizable : false,
						taskbuttonTooltip : "公司详细信息",
						layout : "fit",
						tools : [{
									id : 'refresh',
									handler : Ext.emptyFn,
									scope : this
								}],
						items : [this.getComponents(params)]
					});
		}
		win.show();

	}
});